import 'package:flutter_nb_net/flutter_net.dart';
import 'package:tracker/api/pay/external_order_info_resp.dart';
import 'package:tracker/common/pay/model/order_info_req.dart';
import 'package:tracker/utils/toast_utils.dart';

class PayApi {
  /// 创建外部预订单
  static Future<ExternalOrderInfo?> createExternalPreOrder(OrderInfoReq orderInfoReq) async {
    ExternalOrderInfo? result;
    ToastUtils.showLoading(status: '创建订单...');
    var data = orderInfoReq.toJson();
    var res = await post<ExternalOrderInfoResp, ExternalOrderInfoResp>('/external/order/createPreOrder',
        data: data, decodeType: ExternalOrderInfoResp());
    ToastUtils.dismissLoading();
    res.when(success: (resp) {
      if (resp.code == 200) {
        result = resp.data;
      } else {
        ToastUtils.showToast(resp.msg ?? '创建订单失败');
      }
    }, failure: (msg, code) {
      ToastUtils.showToast('创建订单失败${msg}');
    });
    return result;
  }
}
